﻿<%@ WebService Language="C#" Class="PointsService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
using Expo.Training.DataAccess.Points;
using LitJson;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
[System.Web.Script.Services.ScriptService]
public class PointsService  : System.Web.Services.WebService {

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public string GetPoints(string cardIds, string beginDate, string endDate)
    {
        DateTime _beginDate;
        DateTime _endDate;

        try
        {
            _endDate = DateTime.Parse(endDate);
            _beginDate = string.IsNullOrEmpty(beginDate.Trim())?_endDate.AddYears(-1):DateTime.Parse(beginDate);

            List<PointEntity> _list = new List<PointEntity>();
            _list = PointsModule.GetPoints(cardIds, _beginDate, _endDate);
            return JsonMapper.ToJson(_list);
            
        }
        catch(Exception e)
        {
            return e.Message;
        }
        
    }


    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetPointsDetails(string cardIds, string beginDate, string endDate)
    {
        DateTime _beginDate;
        DateTime _endDate;

        try
        {
            _endDate = DateTime.Parse(endDate);
            _beginDate = string.IsNullOrEmpty(beginDate.Trim()) ? _endDate.AddYears(-1) : DateTime.Parse(beginDate);

            List<PointDetailsEntity> _list = new List<PointDetailsEntity>();
            _list = PointsModule.GetPointsDetails(cardIds, _beginDate, _endDate);
            return JsonMapper.ToJson(_list);

        }
        catch (Exception e)
        {
            return e.Message;
        }

    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetPointDetails(string cardIds, string beginDate, string endDate)
    {
        DateTime _beginDate;
        DateTime _endDate;

        try
        {
            _endDate = DateTime.Parse(endDate);
            _beginDate = string.IsNullOrEmpty(beginDate.Trim()) ? _endDate.AddYears(-1) : DateTime.Parse(beginDate);

            PointDetailsEntity _model = new PointDetailsEntity();
            _model = PointsModule.GetPointDetails(cardIds, _beginDate, _endDate);
            return JsonMapper.ToJson(_model);

        }
        catch (Exception e)
        {
            return e.Message;
        }

    }
    
    
    
}